package clientserver;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;

public class ClientSocketExample {
	public static void main(final String[] args) {
		try {
			//
			// Create a connection to the server socket on the server
			// application
			//
			final InetAddress host = InetAddress.getLocalHost();
			final Socket socket = new Socket("192.168.0.103", 8999);

			//
			// Send a message to the client application
			//
			final ObjectOutputStream oos = new ObjectOutputStream(
					socket.getOutputStream());
			oos.writeObject("Hello There...");

			//
			// Read and display the response message sent by server application
			//
			final ObjectInputStream ois = new ObjectInputStream(
					socket.getInputStream());
			final String message = (String) ois.readObject();
			System.out.println("Message: " + message);

			ois.close();
			oos.close();
		} catch (final UnknownHostException e) {
			e.printStackTrace();
		} catch (final IOException e) {
			e.printStackTrace();
		} catch (final ClassNotFoundException e) {
			e.printStackTrace();
		}
	}
}
